package com.alan.libapi.api;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @ClassName:  IALSocket
 * @Description:  the interface of socketHelper
 * @author: jajuan.wang  
 * @date:   2015-08-16 10:00  
 * version:1.0.0
 */ 
public interface IALSocket {
	
	/**
	 * Returns an input stream for this socket.
	 * If this socket has an associated channel then the resulting input stream delegates all of its operations to the channel.
	 * @return an input stream for reading bytes from this socket
	 * @throws IOException 
	 */
	public InputStream getInputStream() throws IOException;
	
	/**
	 * Returns an output stream for this socket.
	 * If this socket has an associated channel then the resulting output stream delegates all of its operations to the channel.
	 * @return an output stream for writing bytes to this socket.
	 * @throws IOException 
	 */
	public OutputStream getOutputStream() throws IOException;
	
	/**
	 * send data
	 * @param data the data that needs to send 
	 * @return Whether sent successfully
	 * @throws IOException
	 */
	public boolean sendData(byte[] data) throws IOException;
	
	/**
	 * receive data,the method blocks until there is data come
	 * @return received data
	 * @throws Exception
	 */
	public byte[] receiveData() throws Exception;
	
	/**
	 * try connects this socket to the server
	 * @throws IOException
	 */
	public void connect() throws IOException;
	
	/**
	 * Enable/disable connectTimeOut with the specified timeout, in milliseconds.
	 * @param timeout
	 */
	public void setConnectTimeOut(int timeout);
	
	/**
	 * Used to determine whether the connection is maintained
	 * @return whether the connection is maintained
	 */
	public boolean isAlive();
	
	/**
	 * close the socket
	 * @throws IOException 
	 */
	public void closeSocket() throws IOException;
}
